package com.vlong.town.service.banner;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.vlong.town.entity.banner.BannerInfo;
import com.vlong.town.mapper.banner.BannerInfoMapper;

/**
 * Banner图信息业务实现类
 * @author Assassin
 */
@Service
public class BannerInfoService {

    // Fields

    @Autowired
    private BannerInfoMapper bannerInfoMapper;// Banner图信息Mapper接口

    // Methods

    /**
     * 添加Banner图信息
     * @param townId 村镇Id
     * @param type Banner图类型
     * @param title Banner图标题
     * @param content Banner图内容
     * @param url Banner图
     * @param link 链接地址
     * @param color 标题颜色
     */
    @Transactional
    public void add(Long townId, Integer type, String title, String content, String url, String link, String color) {
        BannerInfo bannerInfo = new BannerInfo();
        bannerInfo.setTownId(townId);
        bannerInfo.setType(type);
        bannerInfo.setState(1);
        bannerInfo.setStatus(1);
        bannerInfo.setTitle(title);
        bannerInfo.setContent(content);
        bannerInfo.setUrl(url);
        bannerInfo.setLink(link);
        bannerInfo.setColor(color);
        this.bannerInfoMapper.insert(bannerInfo);
    }

    /**
     * 逻辑删除Banner图信息
     * @param bannerId 主键值
     */
    @Transactional
    public void delete(Long bannerId) {
        this.bannerInfoMapper.delete(bannerId);
    }

    /**
     * 修改Banner图信息
     * @param bannerId Banner图Id
     * @param title Banner图标题
     * @param content Banner图内容
     * @param url Banner图
     * @param link 链接地址
     * @param color 标题颜色
     */
    @Transactional
    public void update(Long bannerId, String title, String content, String url, String link, String color) {
        BannerInfo bannerInfo = new BannerInfo();
        bannerInfo.setBannerId(bannerId);
        bannerInfo.setTitle(title);
        bannerInfo.setContent(content);
        bannerInfo.setUrl(url);
        bannerInfo.setLink(link);
        bannerInfo.setColor(color);
        this.bannerInfoMapper.update(bannerInfo);
    }

    /**
     * 主键查询Banner图信息
     * @param bannerId Banner图Id
     * @return
     */
    @Transactional(readOnly = true)
    public BannerInfo queryById(Long bannerId) {
        return this.bannerInfoMapper.selectById(bannerId);
    }

    /**
     * 查询Banner图信息
     * @param type Banner图类型
     * @param title Banner图标题
     * @param content Banner图内容
     * @return List<BannerInfo>
     */
    @Transactional(readOnly = true)
    public List<BannerInfo> queryList(Integer type, String title, String content) {
        BannerInfo bannerInfo = new BannerInfo();
        bannerInfo.setType(type);
        bannerInfo.setTitle(title);
        bannerInfo.setContent(content);
        return this.bannerInfoMapper.selectList(bannerInfo);
    }
    
    /**
     * 查询Banner图信息
     * @param type Banner图类型
     * @param title Banner图标题
     * @param content Banner图内容
     * @return List<BannerInfo>
     */
    @Transactional(readOnly = true)
	public List<BannerInfo> queryTouristList(Integer type, String title, String content) {
		BannerInfo bannerInfo = new BannerInfo();
        bannerInfo.setType(type);
        bannerInfo.setTitle(title);
        bannerInfo.setContent(content);
        return this.bannerInfoMapper.selectTouristList(bannerInfo);
	}

}
